package com.burst.reptile.modular.web.service.impl;

import com.burst.reptile.common.exception.CustomException;
import com.burst.reptile.common.utils.ToolUtil;
import com.burst.reptile.modular.web.entity.ZpAvatar;
import com.burst.reptile.modular.web.mapper.ZpAvatarMapper;
import com.burst.reptile.modular.web.service.IZpAvatarService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 推荐头像列表 服务实现类
 * </p>
 *
 * @author wujin
 * @since 2020-07-23
 */
@Service
public class ZpAvatarServiceImpl extends ServiceImpl<ZpAvatarMapper, ZpAvatar> implements IZpAvatarService {

	@Override
	public int add(ZpAvatar avatar) {
		avatar.setSmUrl(avatar.getUrl());
		return this.baseMapper.insert(avatar);
	}

	@Override
	public int edit(ZpAvatar avatar) {
		Integer id = avatar.getId();
		if(ToolUtil.isEmpty(id)) {
			throw new CustomException("缺少参数");
		}
		ZpAvatar byId = this.getById(id);
		if(ToolUtil.isEmpty(byId)) {
			throw new CustomException("资源不存在");
		}
		byId.setName(avatar.getName());
		byId.setUrl(avatar.getUrl());
		byId.setSmUrl(avatar.getUrl());
		return this.baseMapper.updateById(byId);
	}

	@Override
	public int del(String id) {
		ZpAvatar byId = this.getById(id);
		if(ToolUtil.isEmpty(byId)) {
			throw new CustomException("资源不存在");
		}
		return this.baseMapper.deleteById(id);
	}

}
